<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册 - 医院药品管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">

    <style>
        html, body {width: 100%; height: 100%; overflow: hidden}
        body {background: #1E9FFF;}
        body:after {content:''; background-repeat:no-repeat; background-size:cover; filter:blur(3px); position:absolute; top:0; left:0; right:0; bottom:0; z-index:-1;}
        .layui-container {width: 100%; height: 100%; overflow: hidden}
        .admin-login-background {width:360px; height:400px; position:absolute; left:50%; top:40%; margin-left:-180px; margin-top:-200px;}
        .logo-title {text-align:center; letter-spacing:2px; padding:14px 0;}
        .logo-title h1 {color:#1E9FFF; font-size:25px; font-weight:bold;}
        .login-form {background-color:#fff; border:1px solid #fff; border-radius:3px; padding:14px 20px; box-shadow:0 0 8px #eeeeee;}
        .login-form .layui-form-item {position:relative;}
        .login-form .layui-form-item label {position:absolute; left:1px; top:1px; width:38px; line-height:36px; text-align:center; color:#d2d2d2;}
        .login-form .layui-form-item input {padding-left:36px;}
        .error-msg {color: red; text-align: center; margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="/register" method="post">
                <div class="layui-form-item logo-title">
                    <h1>用户注册</h1>
                </div>
                <div class="error-msg" th:text="${msg}"></div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username" for="username"></label>
                    <input type="text" name="username" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="password"></label>
                    <input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="confirm_password"></label>
                    <input type="password" name="confirm_password" required lay-verify="required|confirmPass" placeholder="确认密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-group" for="user_role"></label>
                    <select name="user_role" required lay-verify="required" class="layui-input">
                        <option value="">请选择角色</option>
                        <option value="用户">用户</option>
                        <option value="管理员">管理员</option>
                    </select>
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-cellphone" for="user_number"></label>
                    <input type="text" name="user_number" required lay-verify="required|phone" placeholder="手机号" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-email" for="user_email"></label>
                    <input type="email" name="user_email" required lay-verify="required|email" placeholder="邮箱" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button id="btn-register" class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="register">注册</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script th:src="@{/layui/layui.all.js}" charset="utf-8"></script>
<script th:src="@{/lib/jq-module/jquery.particleground.min.js}" charset="utf-8"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        var ctxPath = /*[[@{/}]]*/ '/';

        layui.use(['form', 'layer'], function () {
            var form = layui.form,
                layer = layui.layer;

            form.verify({
                confirmPass: function(value, item) { // value：表单的值、item：表单的DOM对象
                    if (value !== $('input[name="password"]').val()) {
                        return '两次密码输入不一致';
                    }
                }
            });

            // 注册操作
            form.on('submit(register)', function (data) {
                var formData = data.field;
                $.post(ctxPath + "register", formData, function (result) {
                    layer.msg(result.msg, {icon: result.icon, anim: result.anim});
                    if (result.code === "1") {
                        window.location.href = ctxPath + "login"; // 注册成功后跳转到登录页面
                    }
                });
                return false;
            });

            // 粒子线条背景
            $('.layui-container').particleground({
                dotColor:'#7ec7fd',
                lineColor:'#7ec7fd'
            });
        });
    });

</script>
</body>
</html>
